home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-10-06 | 2.0 KB | 50 lines | [TEXT/ttxt] |
- -- This script demonstrates using AppleScript with MacHTTP to generate
- -- dynamic World Wide Web documents.
- --
- -- MacHTTP will only read and execute scripts that have been saved as
- -- text only. Once the script is loaded by MacHTTP, it is passed to the default
- -- scripting system (usually AppleScript) for your server for execution.
- -- MacHTTP prepends the script's source code with a line that is the equivalent of:
- -- set http_request to "<request from client>"
- -- where <request from client> is the actual data received from the WWW client.
- --
- -- The result of the script execution is then returned to the client as a HTML
- -- document. The following script shows how to turn AppleScript results into HTML.
-
- set file_path to ":" -- if this script is in a subdirectory below MacHTTP, change this to the proper relative path
-
- -- Create the title for the HTML document
-
- set header to "<title>Script Test One</title><h1>This is a test:</h1>"
-
- -- Add some text to the body of the document
-
- set body to "This is a test of special chars. See \"Spot\" run! Here's a backslash -> \\"
-
- -- Show the current time on the server
-
- set body to body & "<h2>The time is:</h2>" & (current date)
-
- -- The following shows how to reference the args passed in from MacHTTP
-
- set args to "<h2>Arguments passed in:</h2>" & http_request
- set search_args to "<h2>Search arguments:</h2>" & http_search_args
-
- -- Show all the files in the folder "file_path" and turn HTML files into anchors
-
- set filelist to "<h2>Files on the server:</h2><ul>"
- set listing to (list folder file file_path)
- repeat with i from 1 to the number of items in listing
- set one_file to item i of listing
- if one_file contains ".html" or one_file contains ".script" then
- set filelist to filelist & "<li><a href=\"" & one_file & "\">" & one_file & "</a>"
- else
- set filelist to filelist & "<li>" & one_file
- end if
- end repeat
- set filelist to filelist & "</ul>"
-
- -- send it all back to the server for transmission to the client
-
- return header & body & args & search_args & filelist
-